


***************************************************************;
** Create 2010 denominator file matched with HEDIS 2010 data **;
***************************************************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


data xwalk0; set raw.hic_bene_xwalk_2010;

     if sex_match=1;  /** more stricker match than hic_match lose 0.1% **/
     hic_number=orig_hic;
     
data xwalk; set xwalk0;

     keep hic_number bene_id;

     proc sort nodupkey; by hic_number;
     proc sort nodupkey; by bene_id;

     proc sort; by bene_id;

      /** 542 HIC with Double BENE_ID and 1 with triple BENE_ID only 1 kept **/
      

data denom0; set raw.denom2010;

  /** select variables to keep **/

keep BENE_ID               STATE_CODE             BENE_COUNTY_CD    
     BENE_ZIP_CD           BENE_BIRTH_DT          BENE_SEX_IDENT_CD
     BENE_RACE_CD          RTI_RACE_CD            BENE_AGE_AT_END_REF_YR 
     BENE_HMO_IND_01--BENE_HMO_IND_12
     BENE_HI_CVRAGE_TOT_MONS   BENE_HMO_CVRAGE_TOT_MONS     
     BENE_VALID_DEATH_DT_SW    BENE_DEATH_DT
     BENE_ENROLLMT_REF_YR              
     DUAL_STUS_CD_01--DUAL_STUS_CD_12 ;

  ********************************************************;
  ** Merge HEDIS dataset and Denominator file via XWALK **;
  ********************************************************;

data denom; set denom0;

     denom_flag=1;
     
     sex  = 1*BENE_SEX_IDENT_CD;
     age  = BENE_AGE_AT_END_REF_YR -1;  /** convert to Age at the Begining to consistent with previous years **/

     length rti_racec gender agec $ 10;

          if rti_race_cd = '1' then rti_racec='1.White';
     else if rti_race_cd = '2' then rti_racec='2.Black';
     else if rti_race_cd = '5' then rti_racec='3.Hispanic';
     else if rti_race_cd = '4' then rti_racec='4.Asian';
     else                           rti_racec='5.Other';

     if rti_racec='1.White'    then white=1;    else white=0;
     if rti_racec='2.Black'    then black=1;    else black=0;
     if rti_racec='3.Hispanic' then hispanic=1; else hispanic=0;
     if rti_racec='4.Asian'    then asian=1;    else asian=0;
     if rti_racec='5.Other'    then othrace=1;  else othrace=0;

     if sex=1 then gender='1.Male';
     if sex=2 then gender='2.Female';

     if age>0   and age<60 then agec='1.<60';
     if age>=60 and age<65 then agec='2.60-64';
     if age>=65 and age<70 then agec='3.65-69';
     if age>=70 and age<75 then agec='4.70-74';
     if age>=75 and age<80 then agec='5.75-79';
     if age>=80 and age<85 then agec='6.80-84';
     if age>=85            then agec='7.85+';

     proc freq;
          tables agec gender rti_racec;

     proc sort; by bene_id;

data new.hedis10denom; merge xwalk(in=ok) denom; by bene_id;

     if ok;
     if denom_flag=. then denom_flag=0;

     proc freq; 
          tables denom_flag;

endsas;

